function query_reimburse(page) {
	sys_loading();
	var parm = $('#queryForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('reimburse-query');
	sys_record_parm('reimburse',parm);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#ResultList').html(result);
		}
	});
}


function aidExecute_reimburse(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				sys_msg('操作成功!');
				query_reimburse();
			} else {
				sys_warning('操作失败', '操作失败，请刷新页面再次尝试，如果问题依然存在，请联系管理员!');
			}
		}
	});
}

function showDetail_reimburse(code) {
	var parm = {'code':code};
	var url = create_url('reimburse-detail');
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'600px', height: '600px', open:true});
}

function shield_reimburse(code, title) {
	$.Zebra_Dialog('确认要屏蔽标题为： ' + title + ' 的申请单信息吗？',{
	'type': 'question','title': '警告' ,'buttons':[
       {caption:'屏蔽',callback:function() {
    	   var url = create_url('reimburse-shield');
    	aidExecute_reimburse(code, url);
		}},
    {caption:'取消',callback:function(){}
	}]
	});
}

function unshield_reimburse(code, title) {
	$.Zebra_Dialog('确认要解除标题为： ' + title + ' 申请单的屏蔽状态吗？',{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
       {caption:'解除',callback:function() {
    	   var url = create_url('reimburse-unshield');
    	aidExecute_reimburse(code, url);
		}},
       {caption:'取消',callback:function(){}
	}]
	});
}
/*************************************************edit*****************************/

function select_reimburse(btn) {
	var i = btn.attr('pib');
	var parm = {'index':i};
	var url = create_url('reimburse-aidInit');
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'900px', height:'700px', open:true, 
		onClosed:function(){
		}
	});
}
//查询车辆
function aidQuery_reimburse(page) {
	sys_loading();
	var parm = $('#queryForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('reimburse-aidList');
	$.ajax({type:'POST', url:url, data:parm,success: function(result) {
			sys_loading_close();
			$('#resultList').html(result);
			}
		});
	}

//选择车辆
function choose_reimburse(code,name) {
	console.log(code.name);
	  var p =	$('#aid_g_p').val();
		$('#rcc_' + p).val(code);
		$('#rcn_' + p).val(name);
		$.fn.colorbox.close();
	}


function delete_reimburse(btn) {
	btn.parents('.rep').remove();
	createTitle_reimburse();
	countTotalPrice();
}
function createTitle_reimburse() {
	var title = '';
	var temp = null;
	$('#detailListBody').find('.rep').each(function () {
		temp = $(this).find('.project').val();
		if ('' != temp) {
			title += temp;
			temp = $(this).find('.cou').val();
			if ('' != temp)
				title += '(' + temp  +')';
			title += '    ';
		}
	});
	
	$('#title').val(title);
}

function addDetail_reimburse() {
	var tr = $('#tempTable').find('tr').clone(true);
	var i = $('#index').val();
	tr.find('.project').attr('id', 'project_' + i).attr('name', 'itemList[' + i + '].project').end()
		.find('.rcn').attr({'id':'rcn_' + i, 'name':'itemList[' + i + '].rcn'}).end()
		.find('.btn-primary').attr('pib', i).end()
		.find('.rcc').attr({'id': 'rcc_' + i, 'name': 'itemList[' + i + '].rcc'}).end()
		.find('.cou').attr('name', 'itemList[' + i + '].amount').end()
		.find('.u').attr('name', 'itemList[' + i + '].num').end()
		.find('.re').attr('name', 'itemList[' + i + '].remark').end();
	
	$('#detailListBody').append(tr);
	$('#index').val(parseInt(i) + 1);
}

function save_reimburse() {
	// 检查数量是否为空
	var ok = false;
	$('#editForm').find('.not-null').each(function(e) {
		if ('' == this.value || undefined == this.value) {
			$(this).css('border-color','red');
			ok = true;
			console.log(ok);
		} 
	});
	
	if (ok == true) {
		sys_msg('不能为空,如果不需要保存的请删除在保存！');
		return false;
	}
	var v = $('#editForm').find('#title').val();
    if(v.length > 100){
        alert('亲，标题长度不能超过100哦,请修改！');
        return false;
    }
	createTitle_reimburse();
	var parm = $('#editForm').serialize();
	var url = create_url('reimburse-save');
	sys_submiting();
	$.ajax({type: 'POST',url: url,data: parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_load_handle('reimburse');
			} else if (result == 'parameter_error'){
				sys_msg('您还有选项没有填写哦!不填写数量或商品是不会保存的！ 请检查  -_-');
			} else if (result == 'exists'){
				sys_msg('还没有配置审核流程，不能提交，请尽快配置流程!');
			} else {
				sys_msg('操作失败!');
			}
		}
	});
}
function add_reimburse(btn) {
	var url = create_url('reimburse-aidEdit');
	$.colorbox({overlayClose:false, href:url, close:'[关闭]', width:'500px', height:'400px', open:true, 
		onClosed:function(){
		}
	});
}
function addType_reimburse() {
	var parm = $('#editTypeForm').serialize();
	console.log("ww");
	var url = create_url('reimburse-add');
	sys_submiting();
	$.ajax({type: 'POST',url: url,data: parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功!');
			} else if (result == 'parameter_error'){
				sys_msg('您还有选项没有填写哦!不填写数量或商品是不会保存的！ 请检查  -_-');
			} else {
				sys_msg('操作失败!');
			}
		}
	});
}